package com.teach.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

/**
 *自定义过滤器
 * @author zpw
 *
 */
//@WebFilter("/*")
public class MyFilter implements Filter{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * doFilter 过滤的方法
	 * ServletRequest 请求
	 * ServletRequest 响应
	 * FilterChain  链
	 */
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)   //通过doFilter方法执行过滤任务。
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)arg0;
		System.out.println("开始"+request.getRequestURI());
		arg2.doFilter(arg0, arg1);    //执行过滤链访问本身资源，不写则程序到此结束
		System.out.println("结束");
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
